package com.etheart.framework.core.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.etheart.framework.core.FrameworkCoreException;

public class DateUtils {
	public static Date parseDate(String dateStr) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return sdf.parse(dateStr);
		} catch (ParseException e) {
			throw new FrameworkCoreException("日期转化错误", e);
		}
	}
	
	public static Date parseTime(String dateStr) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			return  sdf.parse(dateStr);
		} catch (ParseException e) {
			throw new FrameworkCoreException("时间转化错误", e);
		}
	}
	public static String formatTime(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return  sdf.format(date);
	}
	public static String formatDate(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return  sdf.format(date);
	}
	
	public static Timestamp parseTimestamp(String dateStr) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date d= sdf.parse(dateStr);
		return new Timestamp(d.getTime());
	}
}
